package com.ruoyi.web.controller.applet;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.file.OssUploadUtils;
import com.ruoyi.system.domain.TudaOrderTransfer;
import com.ruoyi.system.domain.TudaRegion;
import com.ruoyi.system.model.param.*;
import com.ruoyi.system.model.result.*;
import com.ruoyi.system.service.ITudaRegionService;
import com.ruoyi.system.service.IUserOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName UserOrderController
 * @Description TODO
 * @Author Admin
 * @Date 2023/7/14 12:04
 * @Version 1.0
 **/
@RestController
@RequestMapping("/applet/order")
@Api(tags = "小程序运单相关")
public class UserOrderController {

    @Resource
    private IUserOrderService userOrderService;
    @Resource
    private ITudaRegionService regionService;


    @ApiOperation("运单列表")
    @PostMapping("/list")
    public R<OrderInfoResult> getList(@RequestBody QueryOrderListParam param) {
        return userOrderService.getList(param);
    }

    @ApiOperation("我的-展示数据列表")
    @PostMapping("/getUserList")
    public R<OrderInfoResult> getUserList(@RequestBody QueryUserOrderListParam param) {
        return userOrderService.getUserList(param);
    }

    @ApiOperation("运单详情")
    @PostMapping("/info")
    public R<OrderTInfoResult> getInfo(@RequestBody GetOrderInfoParam param) {
        return userOrderService.getInfo(param);
    }

    @ApiOperation("中转落站")
    @PostMapping("/getOrderList")
    public R<NewOrderListResult> getOrderList(Long orderId){
        return userOrderService.getOrderTransferList(orderId);
    }

    @ApiOperation("中转信息编辑")
    @PostMapping("/updateTransfer")
    public R updateTransfer(@RequestBody OrderTransferResult orderTransfer){
        return userOrderService.updateTransfer(orderTransfer);
    }

    @ApiOperation("建单")
    @PostMapping("/add")
    public R addOrder(@RequestBody @Validated AddOrderParam params) {
        return userOrderService.addOrder(params);
    }

    @ApiOperation("业务员列表")
    @PostMapping("/queryUserInfo")
    public R<List<UserListResult>> queryUserInfo(){
        return userOrderService.queryUserInfo();
    }

//    @ApiOperation("确认提车")
//    @PostMapping("/carOk")
//    public R carOk(@RequestBody @Validated CarOkParam param) {
//        return userOrderService.carOk(param);
//
//    }
//
//    @ApiOperation("确认信息")
//    @PostMapping("/confirm")
//    public R confirm(@RequestBody @Validated CarOkParam param) {
//        return userOrderService.confirm(param);
//    }
//
//
//    @ApiOperation("确认车已到站点（中转运输中）")
//    @PostMapping("/confirmSignFor")
//    public R confirmSignFor(@RequestBody GetOrderInfoParam param){
//        return userOrderService.confirmSignFor(param);
//    }
//
//    @ApiOperation("终点签收")
//    @PostMapping("/endSignFor")
//    public R endSignFor(@RequestBody GetOrderInfoParam param){
//        return userOrderService.endSignFor(param);
//    }
//
//    @ApiOperation(value = "地址三级联动")
//    @GetMapping("/threeLevelLink")
//    @ApiImplicitParams({@ApiImplicitParam(name = "parentId", value = "列表Id，获取一级可不填，或 0"),
//            @ApiImplicitParam(name = "level", value = "1, 2, 3")})
//    public R<List<TudaRegion>> threeLevelLink(String parentId, Integer level) {
//        return regionService.threeLevelLink(parentId, level);
//    }

    @ApiOperation(value = "上传图片")
    @PostMapping("/ivManagement/upload")
    public R<String> upload(@RequestPart("file") MultipartFile file) {
        String fileSavePath = "";
        String filename = file.getOriginalFilename();
        try {
            boolean imageFile = OssUploadUtils.checkFileSize(file.getSize(), 20, "M");
            if (!imageFile) {
                return R.fail("上传图片不能超过10m");
            }
            if (filename.toUpperCase().indexOf(".JPG") > 0 || filename.toUpperCase().indexOf(".PNG") > 0 || filename.toUpperCase().indexOf(".JPEG") > 0) {
                fileSavePath = OssUploadUtils.ossUpload(file.getInputStream());
            } else {
                return R.fail("图片不符合格式");
            }
        } catch (Exception e) {
            return R.fail("上传时网络异常，请重试");
        }
        return R.ok(fileSavePath);
    }

//    @ApiOperation("直接付款")
//    @PostMapping("/payMoney")
//    public R payMoney(@RequestBody PayMoneyParam param) {
//        return userOrderService.payMoney(param);
//    }

//    @ApiOperation("返回二维码")
//    @PostMapping("/toWxQrPay")
//    public R toWxQrPay(@RequestBody PayMoneyParam param) {
//        return userOrderService.toWxQrPay(param);
//    }
//
//    @ApiOperation("获取运单支付状态")
//    @PostMapping("/queryOrderPayType")
//    public R queryOrderPayType(@RequestBody PayMoneyParam param){
//        return userOrderService.queryOrderPayType(param);
//    }

    @RequestMapping(value = "/wxMiniNotify")
    public void wxMiniNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        userOrderService.wxMiniNotify(request, response);
    }

}
